/*************************************************************
 * @file pid.h
 * @author MicroOrange
 * @brief 
 * @date 2023/3/1
 *************************************************************/

#ifndef PID_CONTROLLER_H
#define PID_CONTROLLER_H

typedef struct {

    /* Controller gains */
    float Kp;
    float Ki;
    float Kd;

    /* Derivative low-pass filter time constant */
    float tau;

    /* Output limits */
    float limMin;
    float limMax;

    /* Integrator limits */
    float limMinInt;
    float limMaxInt;

    /* Sample time (in seconds) */
    float T;

    /* Controller "memory" */
    float integrator;
    float prevError;			/* Required for integrator */
    float differentiator;
    float prevMeasurement;		/* Required for differentiator */

    /* Controller output */
    float out;

} PIDController;

void   PIDController_Init(PIDController *pid,
                          float Kp,
                          float Ki,
                          float Kd,
                          float limMaxInt,
                          float limMinInt,
                          float limMax,
                          float limMin);
float PIDController_Update(PIDController *pid, float setpoint, float measurement);

#endif
